import type { ResponseOption } from "../../res/ResponseOption.js";
import { hex } from "../../util.js";
import { fields, ResOp } from "./utils.js";

export const idxChange: ResponseOption = {
    name: `0x${hex(ResOp.IdxChange)} 索引寄存器变化通知`,
    description: "由服务端通知客户端，索引寄存器发生变化的消息",
    fields: [
        fields.op(ResOp.IdxChange),
        fields.crc,
        fields.length,
        {
            name: "变量列表",
            kind: "custom",
            desc: "每个变量由 索引(u8) + 值(u16) 组成",
            matcher(data) {
                let str = "";
                while (data.length > 0) {
                    const id = data.u8(0);
                    const value = data.u16le(1);
                    data.consume(3);
                    str += `(${id}) = ${value}\n`;
                }
                return str;
            },
        },
    ],
};
